#include <iostream>
#include <string>

//The qt stuff here
#include <QFile>
#include <QDir>

//the custom part please
#include "camrec.h"

using namespace std;


int main(int argc,char* argv[]){

    if (argc<5){
        cout <<"Invalid argument number"<<endl;
        return 1;
    }

    if(strcmp(argv[1],"move")==0){
       if(! move_file(argv[2],argv[3],argv[4],argv[5]))
           cout << "Something bad happened by moving files" << endl;

    }
    
    return 0;
}

/**
 * Moving a file in a platform independent way with qt
 * @param : they are obvious
 * return : if succesful
 */

bool move_file(char *source_dir,char *dest_dir,char *source_file,char *dest_file){

      //make them qtish
      QString sf_str(source_file);
      QString sd_str(source_dir);
      QString df_str(dest_file);
      QString dd_str(dest_dir);


      //Make the absolute path for destination 
      dd_str.append("/");
      dd_str.append(df_str);

      //The path for destination is :
      //cout << "The destination path is :"<<dd_str.toStdString() << endl; 
      sd_str.append("/");
      sd_str.append(sf_str);
     

      //The files
      QFile df_file;
      df_file.setFileName(dd_str);
      QFile sf_file;
      sf_file.setFileName(sd_str);

     // cout << "The source file is :"<<sd_str.toStdString() << endl;
    
    if(df_file.exists()){
         cout << "The file in the dest already exists :" << df_str.toStdString()<<endl;
         if(!df_file.remove())
            return false;
      }
      
     if (!sf_file.copy(dd_str)){
          cout << "Copying unsuccesfull" << endl;
          return false;
      }

      sf_file.remove();


      return true;
}

